package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划管理相关接口")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 分页查询护理计划列表
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/plan/search")
    @ApiOperation(value = "分页查询护理计划列表")
    public ResponseResult<PageResponse<NursingPlanVo>> queryAll(
           @ApiParam(value = "护理计划名称") String name,
           @ApiParam(value = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
           @ApiParam(value = "每页页数") @RequestParam(defaultValue = "10") Integer pageSize,
           @ApiParam(value = "护理计划状态") Integer status){
           PageResponse<NursingPlanVo> pageResponse = nursingPlanService.queryAll(name,pageNum,pageSize,status);
           return success(pageResponse);
    }

    /**
     * 添加护理计划
     * @param nursingPlanDto
     * @return
     */
    @PostMapping("/plan")
    @ApiOperation(value = "添加护理计划")
    public ResponseResult add(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    /**
     * 根据id查询护理计划
     * @param id
     * @return
     */
    @GetMapping("/plan/{id}")
    @ApiOperation(value = "根据id查询护理计划")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    /**
     * 修改护理计划
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/plan/{id}")
    @ApiOperation(value = "修改护理计划")
    public ResponseResult updateById(@PathVariable Long id,@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updateById(id,nursingPlanDto);
        return success();
    }


    /**
     * 删除护理计划项目
     * @param id
     * @return
     */
    @DeleteMapping("/plan/{id}")
    @ApiOperation(value = "删除护理计划项目")
    public ResponseResult deleteById(@PathVariable Long id ){
        nursingPlanService.deleteById(id);
        return success();
    }

    /**
     * 状态的启用禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "状态的启用禁用")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
           nursingPlanService.updateStatus(id,status);
           return success();
    }
    @GetMapping("/plan")
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<List<NursingPlan>> list(NursingPlan nursingPlan){
        List<NursingPlan> nursingPlanList = nursingPlanService.list(nursingPlan);
        return success(nursingPlanList);
    }
}
